package com.globalwave.pos.payment.service;


import java.util.List;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.globalwave.base.BaseServiceImpl;
import com.globalwave.common.ArrayOrderList;
import com.globalwave.common.C;
import com.globalwave.pos.payment.entity.PaymentLine;
import com.globalwave.system.entity.SessionUser;



@Service("paymentLineBO")
@Scope("prototype")
@Transactional
public class PaymentLineBO extends BaseServiceImpl{
/*
 * 
PAYMENT_METHOD
   code_
   name_
   currency_code
   desc_
   index_

CURRENCY
   code_
   name_
   type_ 0内部/1外部
   


account
  id
  customer_id
  currency_code
  amount_
  useful_life 
  status_
  
account_line
  id
  account_id
  amount_total
  amount_remain
  
  entry_on
  effect_on
  expire_on
  status_
   
 */
	private PaymentLine line ;

	public void add(PaymentLine payment, Payable payableOrder) throws Exception {

		this.line = payment ;
		this.line.setStatus_(C.STATUS_ACTIVE) ;
		this.line.setReturned_amount(C.ZERO_DOUBLE) ;
		this.line.setPayment_date(SessionUser.get().getSale_date()) ;
		
		jdbcDao.insert(this.line) ;
		
		payableOrder.updateByPaymentLine(line) ;
	}
	

	
	public List<PaymentLine> getLines(Short source, Long refId) throws Exception {
		PaymentLine so = new PaymentLine() ;
		so.setRef_source(source) ;
		so.setRef_id(refId) ;
		
		ArrayOrderList orderList = new ArrayOrderList() ;
		orderList.add("line_number") ;
		
		return (List<PaymentLine>)this.jdbcDao.query(so, orderList, PaymentLine.class) ;
	}

	
	public void setLine(PaymentLine line) {
		this.line = line;
	}
	
	public PaymentLine getLine() {
		return line;
	}

	
		
	
}
